/**
 ****************************************************************************************
 *
 * @file ais.h
 *
 * @brief Header file - Letstrong Rope Profile Sensor.
 *
 * Copyright (C) Letstrong 2021-2022
 *
 *
 ****************************************************************************************
 */

#ifndef _AIS_H_
#define _AIS_H_

/*
 * INCLUDE FILES
 ****************************************************************************************
 */
#include "user_config.h"

#if(AIS_TMALL_GENIE_ENABLE)

#include "prf_types.h"
#include "prf.h"
#include "ais_task.h"
#include "attm.h"

/*
 * DEFINES
 ****************************************************************************************
 */
///Maximum number of USER task instances
#define AIS_SENSOR_IDX_MAX     0x01

///AIS Configuration Flag Masks
#define AIS_MANDATORY_MASK              (0xFFFF)


#define AIS_PRIMARY_SVC_UUID            0xFEB3

#define AIS_SVC_READ_CHAR_UUID          0xFED4
#define AIS_SVC_WRITE_CHAR_UUID         0xFED5
#define AIS_SVC_INDICATE_CHAR_UUID      0xFED6
#define AIS_SVC_WR_NO_RSP_CHAR_UUID     0xFED7
#define AIS_SVC_NOTIFY_CHAR_UUID        0xFED8


/*
 * MACROS
 ****************************************************************************************
 */

#define AIS_IS_SUPPORTED(mask)         (((ais_env->prfl_cfg & mask) == mask))

/// Possible states of the BLPS task
enum
{
    /// Idle state
    AIS_IDLE,
    /// Busy state
    AIS_BUSY,

    /// Number of defined states.
    AIS_STATE_MAX
};


///Attributes State Machine
enum
{
	AIS_IDX_SVC = 0,

	AIS_IDX_READ_CHAR,
	AIS_IDX_READ_VAL,
	
	AIS_IDX_WRITE_CHAR,
	AIS_IDX_WRITE_VAL,

	AIS_IDX_IND_CHAR,
	AIS_IDX_IND_VAL,
	AIS_IDX_IND_CFG,
	
	AIS_IDX_WR_NO_RSP_CHAR,
	AIS_IDX_WR_NO_RSP_VAL,
	
	AIS_IDX_NTF_CHAR,
	AIS_IDX_NTF_VAL,
	AIS_IDX_NTF_CFG,

    AIS_IDX_NB,
};

/*
 * TYPE DEFINITIONS
 ****************************************************************************************
 */

/// AIS Profile Sensor environment variable
struct ais_env_tag
{
    /// profile environment
    prf_env_t prf_env;
    /// AIS Service Start Handle
    uint16_t start_hdl;
    /// Feature Configuration Flags
    uint16_t features;
    /// Profile configuration flags
    uint8_t prfl_cfg;
    /// Event (notification/indication) config
    uint8_t evt_cfg;
    /// Environment variable pointer for each connections
    uint8_t ind_cfg[BLE_CONNECTION_MAX];
    /// State of different task instances
    ke_state_t state[AIS_SENSOR_IDX_MAX];
};


/*
 * GLOBAL VARIABLE DECLARATIONS
 ****************************************************************************************
 */

/*
 * FUNCTION DECLARATIONS
 ****************************************************************************************
 */

const struct prf_task_cbs* ais_prf_itf_get(void);
extern void ais_indicate_data(struct ais_ind_upd_req const *param);

/*
 * TASK DESCRIPTOR DECLARATIONS
 ****************************************************************************************
 */
extern const struct ke_state_handler ais_default_handler;

#endif 	//#if(AIS_TMALL_GENIE_ENABLE)

/// @} AIS

#endif /* _AIS_H_ */
